# -*- coding: utf-8 -*-
# Copyright 2011-2012 MagiCycles.com
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.


from apis import routes_api

from datastore.common import PAGE_SIZE

from siteutils import render_to_response, errorpage
from siteutils.language import _

def showallroutes(request):
    context = {"option": {"enable_gmap": True, },
               "subtitle": _("Routes"),
               }
    return render_to_response("allroutes.html", context)


def createroute(request):
    context = {"option": {"enable_gmap": True, "enable_gmap_geometry": True},
               "subtitle": _("Add Route"),
               }
    return render_to_response("create_route.html", context)


def showroute(request, routeid):
    res = routes_api.get_by_id(request, long(routeid))
    if res["status"] != "ok":
        return errorpage(res["message"])

    route = res["route"]
    context = {"option": {"enable_gmap": True, "enable_gmap_geometry": True},
               "route": route,
               "subtitle": "%s %s"%(_("Routes"),route.name),
               "pagesize": PAGE_SIZE}
    return render_to_response("show_route.html", context)


def main():
    pass

if __name__ == '__main__':
    main()
